/**
 * @ author kunnisser
 * @ date 2018/3/14
 * @ description: 设置mock数据接口
*/

import Axios from 'axios'
import {MOCK_PATH} from '../utils/dispatchEnv'
import qs from 'qs';

const TIMEOUT = 14e3;

Axios.defaults.withCredentials = true;

const getMock = (url) => {
  return (params) => Axios.get(url, {
    params,
    timeout: TIMEOUT
  })
};

const postMock = (url) => {
  return (params) => {
    let newParams = qs.stringify(params);
    return Axios.post(url, newParams, {
      timeout: TIMEOUT,
      headers: {
        'Content-Type': 'application/x-www-form-urlencoded'
      }
    })
  }
};

const deleteMock = (url) => {
  return (id, params) => Axios.delete(url + '/' + id, {
    params: params,
    timeout: TIMEOUT
  })
};

const putMock = (url) => {
  return params => Axios.put(url, params)
};

const patchMock = (url) => {
  return (id, params) => Axios.patch(url + '/' + id, params, {
    timeout: TIMEOUT
  })
};

// 获取验证码
const getCheckCode = getMock(MOCK_PATH + '/getSmsCode');

// 短信登录
const smsLogin = postMock(MOCK_PATH + '/loginWithSmsCode');

// 获取城市信息
const getCityList = getMock(MOCK_PATH + '/cityList');

// 提交询价
const enquiry = postMock(MOCK_PATH + '/enquiry');

// 查询续保信息
const queryXubaoInfo = getMock(MOCK_PATH + '/queryXubaoInfo');

// 保险信息查询
const queryDictionaryList = getMock(MOCK_PATH + '/dictionaryList');

// 询价列表
const getEnquiryList = getMock(MOCK_PATH + '/enquiryList');

// 提交核保
const addOrder = postMock(MOCK_PATH + '/addOrder');

// 订单详情
const orderInfo = getMock(MOCK_PATH + '/getOrderInfo');

export {
  smsLogin,
  getCityList,
  getCheckCode,
  enquiry,
  queryXubaoInfo,
  queryDictionaryList,
  getEnquiryList,
  addOrder,
  orderInfo
}
